﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SynergyCounts
{
    [Serializable]
    public sealed class Midcover
    {
        public UInt32 type { get; set; }
        public UInt32 midcoverIcon { get; set; }
        public Double xCoordinate { get; set; }
        public Double yCoordinate { get; set; }
        public UInt32 direction { get; set; }
        public String information { get; set; }
        public Midcover()
        {

        }
        public Midcover(UInt32 type, UInt32 midcoverIcon, Double xCoordinate, Double yCoordinate, UInt32 direction, String information)
        {
            this.type = type;
            this.midcoverIcon = midcoverIcon;
            this.xCoordinate = xCoordinate;
            this.yCoordinate = yCoordinate;
            this.direction = direction;
            this.information = information;
        }

        public IReadOnlyList<Midcover> MidcoverParser(String midcovers)
        {
            List<Midcover> midcoverList = new List<Midcover>();

            Char[] rowSplitter = { '\r', '\n' };
            Char[] columnSplitter = { '\t', ';', '|' };

            String[] midcoversArray = midcovers.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries);
            foreach (String midcover in midcoversArray)
            {
                String[] midcoverData = midcover.Split(columnSplitter, StringSplitOptions.None);
                UInt32 type;
                UInt32.TryParse(midcoverData[0], out type);
                UInt32 midcoverIcon;
                UInt32.TryParse(midcoverData[1], out midcoverIcon);
                Double xCoordinate;
                Double.TryParse(midcoverData[2], out xCoordinate);
                Double yCoordinate;
                Double.TryParse(midcoverData[3], out yCoordinate);
                UInt32 direction;
                UInt32.TryParse(midcoverData[4], out direction);
                String information = midcoverData[5];

                midcoverList.Add(new Midcover(type, midcoverIcon, xCoordinate, yCoordinate, direction, information));
            }
            return midcoverList;
        }
    }
}
